package com.fxcalibre;

import java.util.Locale;

import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.geometry.Rectangle2D;
import javafx.scene.Scene;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.control.TextArea;
import javafx.stage.Screen;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;

import com.fxcalibre.db.DummyBD;
import com.fxcalibre.fxml.control.MediaListPanel;
import com.fxcalibre.fxml.control.PeopleListPanel;
import com.fxcalibre.icons.ImageLoader;
import com.fxcalibre.utils.Constants;
import com.fxcalibre.utils.Preferences;

public class JFXMainFrame extends Application
{

	TextArea textArea = new TextArea("Area de texto");

	@Override
	public void start(Stage primaryStage)
	{		
		Locale.setDefault(Locale.ENGLISH);
		DummyBD.initializeDB((String)Preferences.getPreferences().get(Constants.KEY_DB_FILE), false);
		primaryStage.setTitle("FXCalibre");
		// BorderPane borderPane = new BorderPane();
		//
		// borderPane.setTop(new ItemListToolBar());
		// borderPane.setLeft(new ItemListFilterMenu(textArea));
		// borderPane.setCenter(new ItemListTable(textArea));
		// borderPane.setBottom(new ItemListToolBar());

		TabPane tabPane = new TabPane();
		Tab tabA = new Tab();
		tabA.setText("Media");
		tabA.setClosable(false);
		tabA.setGraphic(ImageLoader.getImageView("icon32.png"));

		// tabA.setContent(new ItemListPanel());
		MediaListPanel mediaListPanel = new MediaListPanel();
		mediaListPanel.setPrimaryStage(primaryStage);
		tabA.setContent(mediaListPanel);

		tabPane.getTabs().add(tabA);

		Tab tabB = new Tab();
		tabB.setText("Personas");
		tabB.setClosable(false);
		tabB.setGraphic(ImageLoader.getImageView("user32.png"));
		tabB.setContent(new PeopleListPanel());

		tabPane.getTabs().add(tabB);

		Scene scene = new Scene(tabPane);
		scene.getStylesheets().add("com/fxcalibre/css/litefxcalibre.css");
		Screen screen = Screen.getPrimary();
		Rectangle2D bounds = screen.getVisualBounds();

		primaryStage.setX(bounds.getMinX());
		primaryStage.setY(bounds.getMinY());
		primaryStage.setWidth(bounds.getWidth());
		primaryStage.setHeight(bounds.getHeight());
		primaryStage.setScene(scene);
		primaryStage.show();
		// primaryStage.sizeToScene();
		primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>()
		{

			@Override
			public void handle(WindowEvent arg0)
			{
				System.exit(0);
			}
		});
	}

	public static void main(String[] args)
	{
		launch(args);
	}

}
